﻿<include file="top" />
<div id="msglist">
<include file="MessagesList" />
</div>
<div id="DialogAlert"></div>
<script type="text/javascript">
var names=[];
var locs=[];
var current=0;
var LastTimeLine={$LastTimeLine};
var Page = {$Page};
F(function(){
	AjaxGetInformation();
	if(Page==1)window.setTimeout(LoadFirstPage, 5000);
});
function AjaxGetInformation(){
	while(names.length>0)names.pop();
	F("td.username").each(function(){
		names.push(F(this).attr("rel"));
	});
	Ajax({
		url:"?m=Subscriber&a=getusersbyopenid",
		method:"POST",data:"openids=" + F.encode(names.join(",")),
		dataType:"json",
		succeed:function(msg){
			if(msg && msg.length && msg.length>0){
				for(var i=0;i<msg.length;i++){
					if(msg[i].NickName!=null) F("td[rel='" + msg[i].OpenId + "']").html("<a href=\"?m=Subscriber&OpenId=" + F.encode(msg[i].OpenId) + "\">"+msg[i].NickName+"</a>");
					else F("td[rel='" + msg[i].OpenId + "']").html("未知");
				}
			}
		}
	});
	while(locs.length>0)locs.pop();
	F("td[rel='event']").each(function(){
		if(/^LOCATION\(([\d\.]+)\,([\d\.]+)\)$/igm.test(this.innerHTML)){
			locs.push({src:this,loc:this.innerHTML.replace(/^LOCATION\(([\d\.]+)\,([\d\.]+)\)$/igm,"$1,$2")});
		}
	});
	if(locs.length>0){
		current=0;
		loadLocation();
	}
	F("td[rel='text']").each(function(){
		for(var i=0;i<PublicWechatEmotions.length;i++){
			this.innerHTML = this.innerHTML.replace(PublicWechatEmotions[i].regexp,'<img src="/Contents/Emotions/' + PublicWechatEmotions[i].file + '" />');
			while(this.innerHTML.indexOf(PublicWechatEmotions[i].code)>=0){
				this.innerHTML = this.innerHTML.replace(PublicWechatEmotions[i].code,'<img src="/Contents/Emotions/' + PublicWechatEmotions[i].file + '" />');
			}
		}
	});
}
function loadLocation(){
	if(current>=locs.length)return;
	Ajax({
		url:"?m=Messages&a=getaddressbygps&location=" + locs[current].loc,
		src:locs[current].src,
		succeed:function(msg){this.src.innerHTML=msg;current++;loadLocation();},
		error:function(){current++;loadLocation();},
		ontimeout:function(){current++;loadLocation();}
	});
}
function ShowDetail(id){
	Ajax({
		url:"?m=Messages&a=showdetail&Id=" + id,
		succeed:function(msg){
			F("#DialogAlert").attr("title","详细信息").html(msg).dialog({
				"width":755,"height":500,buttons:{
					"确定":function(){}
				}
			});
		}
	});
}
function LoadFirstPage(){
	Ajax({
		url:"?m=Messages&for=ajax&page={$Page}&OpenId={$OpenId}&LastTimeLine=" +LastTimeLine,
		succeed:function(msg){
			if(/^(\d+)\|/igm.test(msg)){
				var LastTimeLine1 = msg.substr(0,msg.indexOf("|"));
				if( LastTimeLine1!="0")LastTimeLine=LastTimeLine1;
				msg = msg.substr(msg.indexOf("|")+1);
			}
			if(msg!=""){
				F("#msglist").html(msg);
				AjaxGetInformation();
			}
			window.setTimeout(LoadFirstPage, 5000);
		}
	});	
}
function DeleteMuti(frm){
	var val=[];
	F(frm).find('input[name=Id]').each(function(){
		if(this.checked)val.push(this.value);					 
	});
	if(val.length==0){
		F("#DialogAlert").attr("title","批量删除").html("请选择要删除的记录！").dialog({
			"width":400,"height":300,buttons:{
				"确定":function(){}
			}
		});
	}else{
		F("#DialogAlert").attr("title","批量删除").html("确定要删除选中的记录吗？").dialog({
			"width":400,"height":300,buttons:{
				"确定":function(){
					window.location="?m=Messages&page={$Mo.Get.Int.page}&a=delete&Id="+val.join(",");
				}
			}
		});
	}
}
</script>
<js file="/Contents/Scripts/jquery.min.js" />
<js file="/Contents/Scripts/wxeditor.js" />
<include file="foot" />